home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 22 / AACD 22.iso / AACD / Online / Apache / include / apache / scoreboard.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-03-06  |  7.7 KB  |  212 lines

  1. /* ====================================================================
  2.  * The Apache Software License, Version 1.1
  3.  *
  4.  * Copyright (c) 2000 The Apache Software Foundation.  All rights
  5.  * reserved.
  6.  *
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  *
  11.  * 1. Redistributions of source code must retain the above copyright
  12.  *    notice, this list of conditions and the following disclaimer.
  13.  *
  14.  * 2. Redistributions in binary form must reproduce the above copyright
  15.  *    notice, this list of conditions and the following disclaimer in
  16.  *    the documentation and/or other materials provided with the
  17.  *    distribution.
  18.  *
  19.  * 3. The end-user documentation included with the redistribution,
  20.  *    if any, must include the following acknowledgment:
  21.  *       "This product includes software developed by the
  22.  *        Apache Software Foundation (http://www.apache.org/)."
  23.  *    Alternately, this acknowledgment may appear in the software itself,
  24.  *    if and wherever such third-party acknowledgments normally appear.
  25.  *
  26.  * 4. The names "Apache" and "Apache Software Foundation" must
  27.  *    not be used to endorse or promote products derived from this
  28.  *    software without prior written permission. For written
  29.  *    permission, please contact apache@apache.org.
  30.  *
  31.  * 5. Products derived from this software may not be called "Apache",
  32.  *    nor may "Apache" appear in their name, without prior written
  33.  *    permission of the Apache Software Foundation.
  34.  *
  35.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  36.  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  37.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38.  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  39.  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  42.  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  43.  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  44.  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  45.  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  46.  * SUCH DAMAGE.
  47.  * ====================================================================
  48.  *
  49.  * This software consists of voluntary contributions made by many
  50.  * individuals on behalf of the Apache Software Foundation.  For more
  51.  * information on the Apache Software Foundation, please see
  52.  * <http://www.apache.org/>.
  53.  *
  54.  * Portions of this software are based upon public domain software
  55.  * originally written at the National Center for Supercomputing Applications,
  56.  * University of Illinois, Urbana-Champaign.
  57.  */
  58.  
  59. #ifndef APACHE_SCOREBOARD_H
  60. #define APACHE_SCOREBOARD_H
  61.  
  62. #ifdef __cplusplus
  63. extern "C" {
  64. #endif
  65.  
  66. #ifndef WIN32
  67. #if defined(TPF) || defined(NETWARE)
  68. #include <time.h>
  69. #else
  70. #include <sys/times.h>
  71. #endif /* TPF */
  72. #endif
  73.  
  74.  
  75. /* Scoreboard info on a process is, for now, kept very brief --- 
  76.  * just status value and pid (the latter so that the caretaker process
  77.  * can properly update the scoreboard when a process dies).  We may want
  78.  * to eventually add a separate set of long_score structures which would
  79.  * give, for each process, the number of requests serviced, and info on
  80.  * the current, or most recent, request.
  81.  *
  82.  * Status values:
  83.  */
  84.  
  85. #define SERVER_DEAD 0
  86. #define SERVER_STARTING 1    /* Server Starting up */
  87. #define SERVER_READY 2        /* Waiting for connection (or accept() lock) */
  88. #define SERVER_BUSY_READ 3    /* Reading a client request */
  89. #define SERVER_BUSY_WRITE 4    /* Processing a client request */
  90. #define SERVER_BUSY_KEEPALIVE 5    /* Waiting for more requests via keepalive */
  91. #define SERVER_BUSY_LOG 6    /* Logging the request */
  92. #define SERVER_BUSY_DNS 7    /* Looking up a hostname */
  93. #define SERVER_GRACEFUL 8    /* server is gracefully finishing request */
  94. #define SERVER_NUM_STATUS 9    /* number of status settings */
  95.  
  96. /* A "virtual time" is simply a counter that indicates that a child is
  97.  * making progress.  The parent checks up on each child, and when they have
  98.  * made progress it resets the last_rtime element.  But when the child hasn't
  99.  * made progress in a time that's roughly timeout_len seconds long, it is
  100.  * sent a SIGALRM.
  101.  *
  102.  * vtime is an optimization that is used only when the scoreboard is in
  103.  * shared memory (it's not easy/feasible to do it in a scoreboard file).
  104.  * The essential observation is that timeouts rarely occur, the vast majority
  105.  * of hits finish before any timeout happens.  So it really sucks to have to
  106.  * ask the operating system to set up and destroy alarms many times during
  107.  * a request.
  108.  */
  109. typedef unsigned vtime_t;
  110.  
  111. /* Type used for generation indicies.  Startup and every restart cause a
  112.  * new generation of children to be spawned.  Children within the same
  113.  * generation share the same configuration information -- pointers to stuff
  114.  * created at config time in the parent are valid across children.  For
  115.  * example, the vhostrec pointer in the scoreboard below is valid in all
  116.  * children of the same generation.
  117.  *
  118.  * The safe way to access the vhost pointer is like this:
  119.  *
  120.  * short_score *ss = pointer to whichver slot is interesting;
  121.  * parent_score *ps = pointer to whichver slot is interesting;
  122.  * server_rec *vh = ss->vhostrec;
  123.  *
  124.  * if (ps->generation != ap_my_generation) {
  125.  *     vh = NULL;
  126.  * }
  127.  *
  128.  * then if vh is not NULL it's valid in this child.
  129.  *
  130.  * This avoids various race conditions around restarts.
  131.  */
  132. typedef int ap_generation_t;
  133.  
  134. /* stuff which the children generally write, and the parent mainly reads */
  135. typedef struct {
  136. #ifdef OPTIMIZE_TIMEOUTS
  137.     vtime_t cur_vtime;        /* the child's current vtime */
  138.     unsigned short timeout_len;    /* length of the timeout */
  139. #endif
  140.     unsigned char status;
  141.     unsigned long access_count;
  142.     unsigned long bytes_served;
  143.     unsigned long my_access_count;
  144.     unsigned long my_bytes_served;
  145.     unsigned long conn_bytes;
  146.     unsigned short conn_count;
  147. #if defined(NO_GETTIMEOFDAY)
  148.     clock_t start_time;
  149.     clock_t stop_time;
  150. #else
  151.     struct timeval start_time;
  152.     struct timeval stop_time;
  153. #endif
  154. #ifndef NO_TIMES
  155.     struct tms times;
  156. #endif
  157. #ifndef OPTIMIZE_TIMEOUTS
  158.     time_t last_used;
  159. #endif
  160.     char client[32];        /* Keep 'em small... */
  161.     char request[64];        /* We just want an idea... */
  162.     server_rec *vhostrec;    /* What virtual host is being accessed? */
  163.                                 /* SEE ABOVE FOR SAFE USAGE! */
  164. #ifdef AMIGA
  165.     struct MsgPort *childport;
  166. #endif
  167. } short_score;
  168.  
  169. typedef struct {
  170.     ap_generation_t running_generation;    /* the generation of children which
  171.                                          * should still be serving requests. */
  172. } global_score;
  173.  
  174. /* stuff which the parent generally writes and the children rarely read */
  175. typedef struct {
  176.     pid_t pid;
  177. #ifdef OPTIMIZE_TIMEOUTS
  178.     time_t last_rtime;        /* time(0) of the last change */
  179.     vtime_t last_vtime;        /* the last vtime the parent has seen */
  180. #endif
  181.     ap_generation_t generation;    /* generation of this child */
  182. } parent_score;
  183.  
  184. typedef struct {
  185.     short_score servers[HARD_SERVER_LIMIT];
  186.     parent_score parent[HARD_SERVER_LIMIT];
  187.     global_score global;
  188. } scoreboard;
  189.  
  190. #define SCOREBOARD_SIZE        sizeof(scoreboard)
  191. #ifdef TPF
  192. #define SCOREBOARD_NAME        "SCOREBRD"
  193. #define SCOREBOARD_FRAMES        SCOREBOARD_SIZE/4095 + 1
  194. #endif
  195.  
  196. API_EXPORT(void) ap_sync_scoreboard_image(void);
  197. API_EXPORT(int) ap_exists_scoreboard_image(void);
  198.  
  199. API_VAR_EXPORT extern scoreboard *ap_scoreboard_image;
  200.  
  201. API_VAR_EXPORT extern ap_generation_t volatile ap_my_generation;
  202.  
  203. /* for time_process_request() in http_main.c */
  204. #define START_PREQUEST 1
  205. #define STOP_PREQUEST  2
  206.  
  207. #ifdef __cplusplus
  208. }
  209. #endif
  210.  
  211. #endif    /* !APACHE_SCOREBOARD_H */
  212.